package com.eop.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.form.impl.UICombo;
import org.operamasks.faces.user.util.Browser;

import com.base.common.provider.CommonKeySelectItemProvider;

@ManagedBean(name = "eop_editSchnarioBean", scope = ManagedBeanScope.REQUEST)
public class EditSchnarioBean extends BaseSchnarioBean {
	@Inject
	private FacesContext context;
	@Bind(id = "srRangeBigType", attribute = "binding")
	private UICombo srRangeBigType_binding;

	@Bind(id = "srRangeThinType", attribute = "binding")
	protected UICombo srRangeThinType_binding;
	@SaveState
	private String first;

	@BeforeRender
	public void beforeRender(boolean isPostBack) throws Exception {
		if (!isPostBack) {
			id = context.getExternalContext().getRequestParameterMap()
					.get("id");
			if (!"".equals(id) && null != id) {
				sr = schnarioService.getSchnarioById(id);
				if (sr != null) {
					srRangeThinType_items = CommonKeySelectItemProvider
							.getDirectCommonKey(sr.getSrRangeBigType(), false);
					this.getSchnarioProperty(sr);
				}
			}
		}
	}

	@Action(id = "srRangeBigType", event = "onselect", immediate = true)
	public void changeSrRangeBigType() {
		first = srRangeBigType_binding.getSubmittedValue().toString().trim();
		srRangeThinType_items = CommonKeySelectItemProvider.getDirectCommonKey(
				first, false);
		srRangeThinType = null;
		srRangeThinType_binding.resetValue();
		srRangeThinType_binding.repaint();

	}

	@Action(id = "save")
	public void save() {
		sr = schnarioService.getSchnarioById(id);
		this.setSchnarioProperty();
		schnarioService.saveSchnario(sr);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('editSchnarioTab')");
	}
}
